﻿using UnityEngine;
using System.Collections;

public class PyssynPiippu : MonoBehaviour {
	

	// Update is called once per frame
	void Update () {

		// käännytään hiirtä kohti
		Vector3 p = Camera.main.ScreenToWorldPoint(Input.mousePosition);
		p.z = 0f;
		transform.LookAt (p);

		/*
		if (transform.localEulerAngles.z > 330)
			transform.localEulerAngles.Set(transform.localEulerAngles.x,transform.localEulerAngles.y, 330);
		if (transform.localEulerAngles.z < 210)
			transform.localEulerAngles.Set(transform.localEulerAngles.x,transform.localEulerAngles.y, 210);
			*/


	}
	/*
	void LookAtZ(GameObject ob, Vector3 target_pos)
	{
		Vector3 dir = target_pos-ob.transform.position;
		dir.Normalize();
		
		Quaternion target_q = ob.transform.rotation;
		
		if(dir.x > 0f && dir.x > Mathf.Abs(dir.y))// oikeelle
			target_q = Quaternion.LookRotation(target_pos - ob.transform.position,Vector3.down);
		if(dir.x < 0f && dir.x < -Mathf.Abs(dir.y))// vasemmalle
			target_q = Quaternion.LookRotation(target_pos - ob.transform.position,Vector3.up);
		
		if(dir.y > 0f && dir.y > Mathf.Abs(dir.x))// ylös
			target_q = Quaternion.LookRotation(target_pos - ob.transform.position,Vector3.right);
		if(dir.y < 0f && dir.y < -Mathf.Abs(dir.x))// alas
			target_q = Quaternion.LookRotation(target_pos - ob.transform.position,Vector3.left);
		
		target_q.x=0;
		target_q.y=0;

		print (target_q);

		if (target_q.z > 330)
						target_q.z = 330;
		if (target_q.z < 210)
						target_q.z = 210;
		

		
		ob.transform.rotation = target_q;
	}*/
}
